package com.sc.rest.controller;

import com.sc.common.utils.JsonUtils;
import com.sc.rest.pojo.ItemCatResult;
import com.sc.rest.service.ItemCatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by sc on 2017/10/17.
 */
@Controller
@RequestMapping("/item/cat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @RequestMapping(value = "/list",produces = MediaType.APPLICATION_JSON_VALUE+";charset=utf-8")
    @ResponseBody
    public String getItemCatList(String callback){
        ItemCatResult result = itemCatService.getItemCatList();
        String json = JsonUtils.objectToJson(result);
        if(StringUtils.isBlank(callback)){
            return json;
        }
        //不为空,仅支持jsonp
        return callback+"("+json+");";
    }
}
